TimeManager = {}

TimeManager.getServerTime = function()
  return TimeManager.deltaTime + os.time()
end
TimeManager.saveCDTime = function(key, duration, beginTime)
  if beginTime==nil then
    beginTime = TimeManager.getServerTime()
  end
  local tmp = string.format('{"beginTime":%d, "duration":%d}', beginTime, duration)
  CCUserDefault:sharedUserDefault():setStringForKey(key, tmp)
  CCUserDefault:sharedUserDefault():flush()
end
TimeManager.getLeftDuration = function(key)
  local tmp = CCUserDefault:sharedUserDefault():getStringForKey(key)
  local lt=0
  print(tmp)
  if tmp~=nil and tmp~="" then  
    local res = cjson.decode(tmp)
    local dt = TimeManager.getServerTime() - res.beginTime
    lt = res.duration - dt
    if lt<0 then lt=0;end
  end
  return lt
end
